package com.wuax.controller;

import com.wuax.domain.Book;
import com.wuax.domain.vo.LayTableData;
import com.wuax.domain.vo.Result;
import com.wuax.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/book")
public class BookController {

    @Autowired
    private BookService bookService;

    /**
     * 图书列表
     */
    @GetMapping("/list")
    @ResponseBody
    public LayTableData list(Book book) {
        return bookService.list(book);
    }

    /**
     * 添加图书
     */
    @PostMapping("/add")
    @ResponseBody
    public Result add(@RequestBody Book book) {
        return bookService.add(book);
    }

    /**
     * 更新图书
     */
    @PostMapping("/update")
    @ResponseBody
    public Result update(@RequestBody Book book) {
        return bookService.update(book);
    }

    /**
     * 删除图书
     */
    @PostMapping("/delete")
    @ResponseBody
    public Result delete(@RequestParam List<String> bookIds) {
        return bookService.batchDelete(bookIds);
    }

    /**
     * 图书页面
     */
    @GetMapping("/bookPage")
    public String bookPage() {
        return "book";
    }
}
